#include "setedit.h"
#include "ui_setedit.h"
#include <QDebug>
#include <QMessageBox>
#include "dialog.h"
#include "id.h"
#include "mainwindow.h"
#include "teacher.h"
#include "student.h"
#include "bigsave.h"
extern vector<Teacher*>tdata;
extern vector<student*>sdata;
extern id u;
int t=-1,m;
setedit::setedit(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::setedit)
{
    ui->setupUi(this);
    for(unsigned int i=0;i<tdata.size();i++){
        if(tdata[i]->ifhave(u.str1)){
            t=0;
            m=i;
            break;
        }
    }
    for(unsigned int i=0;i<sdata.size();i++){
        if(sdata[i]->ifhave(u.str1)){
            t=1;
            m=i;
            break;
        }
    }
    if(t==0){
        ui->label_4->setText("  职称：");
         ui->label_5->setText("研究方向：");
         ui->lineEdit->setText(tdata[m]->findname());
         ui->lineEdit_2->setText(tdata[m]->findnumber());
         ui->lineEdit_3->setText(tdata[m]->findcollege());
         ui->lineEdit_4->setText(tdata[m]->findlevel());
         ui->lineEdit_5->setText(tdata[m]->finddirection());
    }
    else if(t==1){
        ui->label_4->setText("   类别：");
        ui->label_5->setText("   导师");
        ui->lineEdit->setText(sdata[m]->findname());
        ui->lineEdit_2->setText(sdata[m]->findnumber());
        ui->lineEdit_3->setText(sdata[m]->findcollege());
        ui->lineEdit_4->setText(sdata[m]->findtype());
        ui->lineEdit_5->setText(sdata[m]->findteach());
    }
}

setedit::~setedit()
{
    delete ui;
}

void setedit::on_pushButton_clicked()
{
    closeEvent(0);
    Dialog* p=new(Dialog);
    p->show();
}

void setedit::on_pushButton_2_clicked()
{
    QString str1=ui->lineEdit_3->text();
    QString str2=ui->lineEdit_4->text();
    QString str3=ui->lineEdit_5->text();
    if(str1==""||str2==""||str3==""){
        QMessageBox::information(this,"提示","请确保信息完整");
    }
    else if(t==0){
        tdata[m]->setcollege(str1);
        tdata[m]->setlevel(str2);
        tdata[m]->setdirection(str3);
        bigsave();
        QMessageBox::information(this,"提示","保存成功");
    }
    else if(t==1){
        sdata[m]->setcollege(str1);
        sdata[m]->settype(str2);
        sdata[m]->setteach(str3);
        bigsave();
        QMessageBox::information(this,"提示","保存成功");
    }
}
